﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace XHCTMS.VIEW
{
    public partial class Success : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int teaID;
                try
                {
                    teaID = int.Parse(Request.QueryString["teachingID"]);
                }
                catch
                {
                    return;
                }              

                try
                {
                    this.InfoList.DataSource = new BLL.Success().GetTeachingEndStuInfo(teaID);
                    this.InfoList.DataBind();
                    DataTable dt = new BLL.Success().GetTeachingEndClassInfo(teaID);
                    txtClassName.Text = dt.Rows[0]["class_name"].ToString();
                    txtClassSub.Text = dt.Rows[0]["sub_name"].ToString();
                    txtClassTea.Text = dt.Rows[0]["user_name"].ToString();
                    txtTeaLesson.Text = dt.Rows[0]["teaching_lesson"].ToString();
                    txtTeaTea.Text = dt.Rows[0]["tea_name"].ToString();
                }
                catch
                {
                }
            }
        }



        /// <summary>
        /// 课程ID为100020实验 ，
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int teaID ;
            try
            {
                teaID = int.Parse(Request.QueryString["teachingID"]);
            }
            catch
            {
                return ;
            }
            List<string> lstSql = new List<string>();
            for (int count = 0; count < this.InfoList.Items.Count; count++)
            {
                StringBuilder sb = new StringBuilder();
                string stuID = ((Label)InfoList.Items[count].FindControl("lblReStuID")).Text;
                string perScore = ((Label)InfoList.Items[count].FindControl("lblRePerScore")).Text;
                string checkScore = ((Label)InfoList.Items[count].FindControl("lblReCheckScore")).Text;
                string score = ((TextBox)InfoList.Items[count].FindControl("txtReSucScore")).Text;
                if (string.IsNullOrEmpty(perScore))
                {
                    perScore = "0";
                }
                if (string.IsNullOrEmpty(checkScore))
                {
                    checkScore = "0";
                }
                if (string.IsNullOrEmpty(score))
                {
                    score = "0";
                }
                string total = ((float.Parse(perScore) + float.Parse(checkScore)) * 0.15 + float.Parse(score) * 0.8).ToString();
                sb.Append("insert into success values( "+stuID+","+perScore+","+checkScore+","+score+","+total+","+teaID+
                    " ,convert(varchar(32),GETDATE(),23) ) ;");
                lstSql.Add(sb.ToString());
            }
            int result = new BLL.Success().AddClassTeaStu(lstSql,teaID);
            if (result > 0)
            {
                Response.Redirect("Student_success.aspx");
            }
        }
    }
}